package com.vrp3d.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vrp3d.common.consts.CommonConst;
import com.vrp3d.common.enums.CommonExceptionEnum;
import com.vrp3d.common.response.RestResponse;
import com.vrp3d.domain.dto.dist.DistForFrontDTO;
import com.vrp3d.domain.dto.showroom.*;
import com.vrp3d.service.ShowroomService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @author vrp3d
 */
@Api("展厅信息")
@Slf4j
@Validated
@RestController
@RequestMapping("/showroom")
public class ShowroomController extends AbsController {

    @Autowired
    private ShowroomService showroomService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取展厅列表", response = ShowroomListDTO.class)
    @ApiImplicitParams({
          @ApiImplicitParam(name = "current", value = "当前页码", required = true, paramType = "query", dataType = "int"),
          @ApiImplicitParam(name = "size", value = "每一页展示数量", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "/getShowroomList", method = RequestMethod.GET)
    public RestResponse getShowroomList(@ApiIgnore Page<ShowroomListDTO> page, @Validated ShowroomSearchDTO search,
                                        @RequestParam(defaultValue = CommonConst.PAGE_CURRENT) Integer current,
                                        @RequestParam(defaultValue = CommonConst.PAGE_SIZE) Integer size) {
        page.setCurrent(current);
        page.setSize(size);
        Page<ShowroomListDTO> result = showroomService.getShowroomList(page, search);
        return new RestResponse().put(result);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "判断展厅名称是否可用(新增时)")
    @ApiResponses({
          @ApiResponse(code = 200, message = "展厅名称可用"),
          @ApiResponse(code = 22002, message = "展厅名称已存在")
    })
    @ApiImplicitParam(name = "showroomName", value = "展厅名称", required = true, paramType = "query")
    @RequestMapping(value = "/whetherTheNameOfTheExhibitionHall", method = RequestMethod.GET)
    public RestResponse whetherTheNameOfTheExhibitionHall(@Size(min = 1, max = CommonConst.NAME_LENGTH, message = "展厅名称长度限制1-" + CommonConst.NAME_LENGTH)
                                                          @NotBlank(message = "展厅名称不能为空") String showroomName) {
        showroomService.whetherTheNameOfTheExhibitionHall(showroomName);
        return new RestResponse(CommonExceptionEnum.SHOWROOM_NAME_AVAILABLE.getMsg());
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增展厅")
    @ApiResponses({
          @ApiResponse(code = 200, message = "新增展厅成功"),
          @ApiResponse(code = 22003, message = "新闻分类信息异常")
    })
    @RequestMapping(value = "/insertShowroom", method = RequestMethod.POST)
    public RestResponse insertShowroom(@Validated @RequestBody ShowroomInsertDTO dto) {
        showroomService.insertShowroom(dto);
        return new RestResponse(CommonExceptionEnum.SUCCESSFULLY_ADDED_EXHIBITION_INFORMATION.getMsg());
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "判断展厅名称是否可用(修改时)")
    @ApiResponses({
          @ApiResponse(code = 200, message = "展厅名称可用"),
          @ApiResponse(code = 22002, message = "展厅名称已存在")
    })
    @ApiImplicitParams({
          @ApiImplicitParam(name = "id", value = "展厅id", required = true, paramType = "query", dataType = "int"),
          @ApiImplicitParam(name = "showroomName", value = "展厅名称", required = true, paramType = "query")
    })
    @RequestMapping(value = "/whetherTheNameOfTheExhibitionHallWhenUpdate", method = RequestMethod.GET)
    public RestResponse whetherTheNameOfTheExhibitionHallWhenUpdate(@Size(min = 1, max = CommonConst.NAME_LENGTH, message = "展厅名称长度限制1-" + CommonConst.NAME_LENGTH)
                                                                    @NotBlank(message = "展厅名称不能为空") String showroomName,
                                                                    @Min(value = 1, message = "id最小值为1") @NotNull(message = "id不能不空") Integer id) {
        showroomService.whetherTheNameOfTheExhibitionHallWhenUpdate(id, showroomName);
        return new RestResponse(CommonExceptionEnum.SHOWROOM_NAME_AVAILABLE.getMsg());
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改展厅")
    @ApiResponses({
          @ApiResponse(code = 200, message = "展厅信息修改成功"),
          @ApiResponse(code = 21005, message = "展厅不存在")
    })
    @RequestMapping(value = "/updateShowroom", method = RequestMethod.PUT)
    public RestResponse updateShowroom(@Validated @RequestBody ShowroomUpdateDTO dto) {
        showroomService.updateShowroom(dto);
        return new RestResponse(CommonExceptionEnum.SUCCESSFULLY_UPDATE_EXHIBITION_INFORMATION.getMsg());
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除展厅")
    @ApiResponses({
          @ApiResponse(code = 200, message = "展厅删除成功"),
          @ApiResponse(code = 21005, message = "展厅不存在")
    })
    @ApiImplicitParam(name = "id", value = "展厅id", required = true, paramType = "query", dataType = "int")
    @RequestMapping(value = "/deleteShowroomById", method = RequestMethod.DELETE)
    public RestResponse deleteNewsByIds(@NotNull(message = "id不能不空") @Min(value = 1, message = "id最小值为1") Integer id) {
        showroomService.deleteShowroomById(id);
        return new RestResponse(CommonExceptionEnum.SUCCESSFULLY_DELETED_EXHIBITION_HALL.getMsg());
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "提交展厅为待审核")
    @ApiResponses({
          @ApiResponse(code = 200, message = "提交待审核成功"),
          @ApiResponse(code = 21005, message = "展厅不存在")
    })
    @RequestMapping(value = "/submitReview", method = RequestMethod.PUT)
    public RestResponse submitReview(@RequestBody @Validated ShowroomSubmitReviewDTO dto) {
        showroomService.submitReview(dto.getId());
        return new RestResponse(CommonExceptionEnum.SUBMITTED_FOR_REVIEW_SUCCESSFULLY.getMsg());
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "获取展厅分类信息", response = DistForFrontDTO.class)
    @RequestMapping(value = "/getTypeList", method = RequestMethod.GET)
    public RestResponse getTypeList() {
        List<DistForFrontDTO> result = showroomService.getTypeList();
        return new RestResponse().put(result);
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "获取展厅列表_前台", response = ShowroomListDTO.class)
    @ApiImplicitParams({
          @ApiImplicitParam(name = "current", value = "当前页码", required = true, paramType = "query", dataType = "int"),
          @ApiImplicitParam(name = "size", value = "每一页展示数量", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "/getShowroomListFront", method = RequestMethod.GET)
    public RestResponse getShowroomListFront(@ApiIgnore Page<ShowroomListDTO> page, @Validated ShowroomSearchDTO search,
                                             @RequestParam(defaultValue = CommonConst.PAGE_CURRENT) Integer current,
                                             @RequestParam(defaultValue = CommonConst.PAGE_SIZE) Integer size) {
        page.setCurrent(current);
        page.setSize(size);
        Page<ShowroomListDTO> result = showroomService.getShowroomListFront(page, search);
        return new RestResponse().put(result);
    }

    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "判断展厅审核是否通过")
    @ApiResponses({
          @ApiResponse(code = 200, message = "展厅审核未通过"),
          @ApiResponse(code = 21009, message = "展厅审核已通过")
    })
    @ApiImplicitParams({
          @ApiImplicitParam(name = "id", value = "展厅id", paramType = "query", dataType = "int"),
          @ApiImplicitParam(name = "showroomStatus", value = "状态", required = true, paramType = "query")
    })
    @RequestMapping(value = "/whetherTheStausIspass", method = RequestMethod.PUT)
    public RestResponse statusPass(@RequestBody @Validated ShowroomStatusPassDTO dto) {
        showroomService.statusPass(dto);
        return new RestResponse(CommonExceptionEnum.THE_AUDIT_OF_THE_EXHIBITION_HALL_HAS_BEEN_PASSED.getMsg());
    }

    @ApiOperationSupport(order = 11)
    @ApiOperation(value = "待审核列表", response = ShowroomListReviewDTO.class)
    @ApiImplicitParams({
          @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "query", dataType = "int"),
          @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "/ShowroomListReview", method = RequestMethod.GET)
    public RestResponse ShowroomListReview(@ApiIgnore Page<ShowroomListReviewDTO> page, @Validated ShowroomListReviewDTO dto,
                                           @RequestParam(defaultValue = CommonConst.PAGE_CURRENT) Integer current,
                                           @RequestParam(defaultValue = CommonConst.PAGE_SIZE) Integer size) {
        page.setCurrent(current);
        page.setSize(size);
        Page<ShowroomListReviewDTO> result= showroomService.getShowroomListReview(page,dto);
        return new  RestResponse(CommonExceptionEnum.SUBMITTED_FOR_REVIEW_SUCCESSFULLY.getMsg()).put(result);
    }
}
